<template>
  <div class="details">
    <div class="shareContent">
      <!--                用户信息-->
      <div class="userContent">
        <div class="userLeft">
          <img :src="shareDetail.picUrl && require('../../image/defaultHeadImg.jpeg')" alt />
          <p>{{shareDetail.nickname}}</p>
        </div>
        <!--                    发布时间-->
        <div class="userRight">
          <p>{{$moment(shareDetail.shareTime)}}</p>
        </div>
      </div>
      <!--            内容-->
      <div class="Scontent">
        <p>{{shareDetail.content}}</p>
        <!--            图片-->
        <div class="comment-image">
          <img
            v-for="(i,index) in (shareDetail.imgs || 0)"
            :key="index"
            :src="i && require('../../image/defaultHeadImg.jpeg')"
            alt
          />
        </div>
      </div>

      <!-- 图标 -->
      <div class="share-function">
        <div class="share-function-icon">
          <yd-icon name="share3" size=".32rem"></yd-icon>
          <span>转发</span>
        </div>
        <div class="share-function-icon" @click="showReplyWrapper">
          <yd-icon name="feedback" size=".32rem"></yd-icon>
          <span>评论 {{commentCount || comments.length}}</span>
        </div>
        <div class="share-function-icon">
          <yd-icon name="good" size=".32rem"></yd-icon>
          <span>赞 {{fabulousCount}}</span>
        </div>
      </div>

      <!--                评论-->
      <div class="comments" v-if="comments.length">
        <div class="comment-box" v-for="(comment,index) in comments" :key="index">
          <!--                    评论用户信息-->
          <!-- <div class="comment-top"> -->
          <!-- <div class="comment-userinfo"> -->
          <!-- <img :src="comment.picUrl && require('../../image/1.jpg')" alt /> -->
          <!-- <span>{{comment.nickname}}</span> -->
          <!-- </div> -->
          <!-- <span>{{$moment(comment.createTime)}}</span> -->
          <!-- </div> -->
          <!--    评论内容-->
          <p class="com">
            <router-link to="/" style="color:#e74505">{{comment.nickname}}：</router-link>
            {{comment.content}}
          </p>
        </div>
      </div>
    </div>

    <yd-popup v-model="isSHowReply" position="bottom" height="10%">
      <div class="comment-confirm">
        <yd-textarea
          placeholder="请输入您的评论"
          maxlength="100"
          class="comment-input"
          :show-counter="false"
          v-model="userCommentInput"
        ></yd-textarea>
        <yd-button type="warning" @click.native="send">发送</yd-button>
      </div>
    </yd-popup>
  </div>
</template>

<script>
import { shareDetail } from "@/api";

export default {
  name: "ShareDetail",
  data() {
    return {
      shareDetail,
      comments: [
        { nickname: "提莫", content: "正在送命." },
        { nickname: "SONA", content: "not good." }
      ],
      commentCount: 0,
      fabulousCount: 0,
      isSHowReply: false,
      userCommentInput: ""
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      shareDetail({ id: this.$route.query.id || "" }).then(res => {
        this.shareDetail = res.data.share;
        this.comments = res.data.comments || this.comments;
        this.commentCount = res.data.commentCount || 0;
        this.fabulousCount = res.data.fabulousCount || 0;
      });
    },
    reply() {
      this.isSHowReply = true;
    },
    showReplyWrapper(type) {
      this.isSHowReply = true;
      console.log("评论");
    },
    send() {
      console.log(this.userCommentInput);
      this.isSHowReply = false;
      this.comments.push({
        nickname: Math.random().toFixed(2),
        content: this.userCommentInput
      });
      this.userCommentInput = "";
    }
  }
};
</script>

<style scoped lang='less'>
.details {
  width: 100%;
  height: 100%;
  background: white;
  padding: 0.15rem;
}
.shareContent {
  width: 100%;
  text-align: left;
  padding: 0.15rem;
  background: white;
  margin-bottom: 0.15rem;
}

.Scontent p {
  margin: 0.15rem 0;
  font-size: 0.3rem;
  padding: 0 0.15rem;
  overflow: hidden;
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.userContent {
  display: flex;
  width: 100%;
  height: 1rem;
  /*padding-top:.15rem;*/
}

.userLeft {
  display: flex;
  line-height: 1rem;
  width: 50%;
  font-size: 0.32rem;
  font-weight: 600;
}

.userLeft img {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  margin-right: 0.15rem;
}

.userRight {
  line-height: 1rem;
  width: 50%;
  text-align: right;
}

.comment-image {
  display: flex;
  flex-wrap: wrap;
}

.comment-image img {
  height: 30.75vw;
  width: 30.75vw;
  align-self: flex-start;
  margin: 0.05rem;
  display: block;
}

.comments {
  background-color: #f2f2f2;
  padding: 0.15rem;
  border-radius: 0.15rem;
}

.com {
  font-size: 0.3rem;
  overflow: hidden;
  line-height: 0.5rem;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  // margin-left: 1rem;
  position: relative;
  word-break: break-all;
  // top: -0.25rem;
}

.comment-top {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-top: 0.2rem;
}

.comment-top:after {
  content: "";
  display: block;
  width: calc(100%);
  transform: scaleY(0.33);
  height: 1px;
  background-color: #ccc;
  position: absolute;
  top: -0.2rem;
  right: 0;
}
.comment-top > span {
  display: inline-block;
  width: 50%;
  line-height: 0.8rem;
  color: gray;
  text-align: right;
}

.comment-top span {
  position: relative;
  top: -0.1rem;
}

.comment-top img {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 50%;
  margin-right: 0.2rem;
}

.comment-userinfo {
  width: 50%;
  font-size: 0.28rem;
  font-weight: 600;

  img {
    width: 0.7rem;
    height: 0.7rem;
    display: inline-block;
    vertical-align: middle;
  }

  span {
    vertical-align: middle;
  }
}

.share-function {
  width: 100%;
  display: flex;
  // border: 1px solid #eee;
  margin-bottom: 0.15rem;
}

.share-function-icon {
  flex: 1;
  text-align: center;
  margin: 0.2rem 0;
  border-left: 1px solid #eee;
  font-size: 0.3rem;

  &:first-child {
    border: none;
  }

  span {
    margin-left: 0.15rem;
    letter-spacing: 0.02rem;
  }
}
/* 评论底部 */
.combar {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.1rem;
}
.combar-right {
  margin-right: 0.2rem;
}

.comment-input {
  width: calc(100% - 0.2rem);
  height: 1rem;
  flex: 10;
  margin-right: 0.1rem;
  background: #fff;
  overflow: hidden;
}

/deep/ .comment-input textarea {
  height: 100% !important;
  background-color: #eee;
  font-size: 0.28rem;
  padding: 0.1rem 0;
}

.comment-confirm {
  display: flex;
  height: 100%;
  padding: 0.18rem 0.15rem;
  align-items: center;
  font-size: 0.2rem;
}
</style>